﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _06_枚举
{
    class Program
    {
        static void Main(string[] args)
        {
            Sample01();
            Sample02();
            Sample03();
            Sample04();
            Sample05();
            Console.ReadKey();
        }
        static void Sample01()
        {

            Console.WriteLine("--------实例1：返回集合--------");
            Person p = new Person();
            p.Add(new Person() { Id = 1, Name = "Li", Age = 12 });
            p.Add(new Person() { Id = 2, Name = "Hong", Age = 13 });
            foreach (Person item in p)
            {
                Console.WriteLine("Person对象的Id:{0},Name:{1},Age:{2}", item.Id, item.Name, item.Age);//如何控制插入个数
            }
        }
        static void Sample02()
        {
            Console.WriteLine("--------实例2：最简单的调用IEnumerable返回集合--------");
            Person02 p = new Person02();
            p.Add(new Person02() { Id = 1, Name = "Li" });
            p.Add(new Person02() { Id = 2, Name = "Kim" });
            p.Add(new Person02() { Id = 221, Name = "Tim" });
            foreach (Person02 item in p)
            {
                Console.WriteLine("Person02对象的Id:{0},Name:{1}", item.Id, item.Name);
            }
        }
        static void Sample03()
        {
            Console.WriteLine("--------实例3：调用IEnumerator返回集合--------");
            Person03 p = new Person03();
            p.Add(new Person03() { Id = 1, Name = "Li" });
            p.Add(new Person03() { Id = 2, Name = "Kim" });
            p.Add(new Person03() { Id = 221, Name = "Tim" });
            foreach (Person03 item in p)
            {
                Console.WriteLine("Person对象的Id:{0},Name:{1}", item.Id, item.Name);
            }
        }
        static void Sample04()
        {
            Console.WriteLine("--------实例4：调用IEnumerator返回集合--------");
            Person04 p = new Person04();
            p.Add(new Person04() { Id = 1, Name = "Li" });
            p.Add(new Person04() { Id = 2, Name = "Kim" });
            p.Add(new Person04() { Id = 221, Name = "Tim" });
            foreach (Person04 item in p)
            {
                Console.WriteLine("Person对象的Id:{0},Name:{1}", item.Id, item.Name);
            }
        }
        static void Sample05()
        {
            Console.WriteLine("--------实例5：调用IEnumerator返回集合--------");
            Person05 p = new Person05();
            foreach (int item in p)
            {
                 Console.WriteLine("Person对象的int:{0}",item);
            }
        }
    }
}
